/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   04.05.2010
 * @version SVN: $Id: DeleteProductCommand.java 111 2010-05-07 10:50:22Z f.aarndt@web.de $
 */

package org.cakis.client.commands;

import java.rmi.RemoteException;

import javax.microedition.lcdui.Command;

import org.cakis.client.CakisMIDlet;
import org.cakis.client.forms.ProductExistForm;
import org.cakis.webservice.ProductNotFoundException;

/**
 * DeleteProductCommand
 *
 * @author Florian Arndt
 */
public class DeleteProductCommand extends AbstractCommand {
	private CakisMIDlet midlet;
	private ProductExistForm form;
	
	public DeleteProductCommand(CakisMIDlet midlet, ProductExistForm form) {
		super("Entnehmen", Command.OK, 2);
		this.midlet = midlet;
		this.form = form;
	}

	public void execute() {
		try {
			midlet.getService().deleteStockItem(form.getProduct().getId(), 
					Integer.parseInt(form.getTextField().getString()));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ProductNotFoundException e) {
			e.printStackTrace();
		}
		midlet.handleResumeCommand();
	}
}
